#coding=utf-8

from django.db import models
from django.db import transaction
from django.contrib.sites.models import Site


# Create your models here.

class SiteNews(models.Model):
    """
    An SiteNews that create sitenews.
    #create one sitenews
    >>>sitenews = SiteNews.objects.create();
    """
    sitename=models.CharField(max_length=256);
    originalurl=models.URLField(max_length=512);
    createdate=models.DateTimeField(auto_now=True);
    newscontent=models.TextField();
    newsdate=models.DateField(auto_now_add=True);
    newstitle=models.CharField(max_length=512);
    shuttitle=models.CharField(max_length=512);
    newstype=models.CharField(max_length=512);
    #site = models.ForeignKey(Site)
    
    def get_absolute_url(self):
        return '/jj97/newsdetail/%d/'%(self.id)
    
    def __unicode__(self):
        return u'%d %s'%(self.id,self.shuttitle);
    
class CrawalFailedUrl(models.Model):
    """
    An crawalfailedurl that create object;
    #create on crawalfailedurl
    >>>failedurl = CrawalFailedUrl.objects.create(originalurl='originalurl',crawaldate=current_timestamp,);
    """
    originalurl = models.URLField(max_length=512);
    failedtimestamp = models.DateTimeField(auto_now=True);
    errortype = models.CharField(max_length=512);
    
    def get_absolute_url(self):
        return '/jj97/newsdetail/%d/'%(self.id)
    
    
    def __unicode__(self):
        return self.originalurl;
